package rj.db.suggest;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import rj.db.utils.ConnectionBean;

public class MedicineSuggest
{
	public static ArrayList<String> getMedicineByStartName(String medicine) throws SQLException{
		ArrayList<String> medicines = new ArrayList<String>();
		medicine=medicine.trim();
		medicine=medicine+"%";
		Connection con = ConnectionBean.getConnection();
		PreparedStatement psm=con.prepareStatement("select medname from permedicine where medname LIKE ? order by medname");
		psm.setString(1,medicine);
		ResultSet rs=psm.executeQuery();
		while(rs.next())
		{
			medicines.add(rs.getString("medname"));
		}
		return medicines;
	}
	
	public static ArrayList<String> getMedicineByAllName(String medicine) throws SQLException{
		ArrayList<String> medicines = new ArrayList<String>();
		medicine=medicine.trim();
		medicine="%"+medicine+"%";
		Connection con = ConnectionBean.getConnection();
		PreparedStatement psm=con.prepareStatement("select medname from permedicine where medname LIKE ? order by medname");
		psm.setString(1,medicine);
		ResultSet rs=psm.executeQuery();
		while(rs.next())
		{
			medicines.add(rs.getString("medname"));
		}
		return medicines;
	}
	
	public static ArrayList<String> getMedicineByEndName(String medicine) throws SQLException{
		ArrayList<String> medicines = new ArrayList<String>();
		medicine=medicine.trim();
		medicine="%"+medicine;
		Connection con = ConnectionBean.getConnection();
		PreparedStatement psm=con.prepareStatement("select medname from permedicine where medname LIKE ? order by medname");
		psm.setString(1,medicine);
		ResultSet rs=psm.executeQuery();
		while(rs.next())
		{
			medicines.add(rs.getString("medname"));
		}
		return medicines;
	}
}
